import { getEntityShow } from '../utils/taskUtils'

const state = {
  showCreate: true,
  manager: [],
  workLeader: [],
  liaison: [],
  safeman: [],
  petrolman: [],
  trainChecker: [],
  worker: []
  // showData: initialShowData
}

const mutations = {
  setTaskCreateData(state, data) {
    state[data.key] = data.value
  },
  // setTaskDataStore(state, taskData) {
  //   state.taskData = JSON.parse(JSON.stringify(taskData))
  // },
  initTaskCreateStore(state) {
    state.manager = []
    state.liaison = []
    state.workLeader = []
    state.safeman = []
    state.petrolman = []
    state.trainChecker = []
    state.worker = []
  },
  setShowCreate(state, isShow) {
    state.showCreate = isShow
  }
}

const getters = {
  // taskDataStore: (state) => JSON.parse(JSON.stringify(state.taskData)),
  // workAreaPickerStore: (state) => JSON.parse(JSON.stringify(state.workAreaPicker)),
  showCreate: (state) => state.showCreate,
  workLeader: (state) => state.workLeader,
  manager: (state) => state.manager,
  liaison: (state) => state.liaison,
  safeman: (state) => state.safeman,
  trainChecker: (state) => state.trainChecker,
  worker: (state) => state.worker,
  petrolman: (state) => state.petrolman,
  workLeaderShow: (state) => Array.from(state.workLeader, (item) => getEntityShow(item)).toString(),
  managerShow: (state) => Array.from(state.manager, (item) => getEntityShow(item)).toString(),
  liaisonShow: (state) => Array.from(state.liaison, (item) => getEntityShow(item)).toString(),
  safemanShow: (state) => Array.from(state.safeman, (item) => getEntityShow(item)).toString(),
  trainCheckerShow: (state) => Array.from(state.trainChecker, (item) => getEntityShow(item)).toString(),
  workerShow: (state) => Array.from(state.worker, (item) => getEntityShow(item)).toString(),
  petrolmanShow: (state) => Array.from(state.petrolman, (item) => getEntityShow(item)).toString()
  // workerShow: (state) => {
  //   if (state.worker.type) {
  //     return state.worker.name
  //   } else {
  //     return ''
  //   }
  // }
  // workerShow: (state) => {
  //   if (state.worker.type) {
  //     if (state.worker.type === 'userId') {
  //       return Array.from(state.worker.member, (item) => item.name).toString()
  //     } else if (state.worker.type === 'userGroup') {
  //       return state.worker.name
  //     } else {
  //       return ''
  //     }
  //   } else {
  //     return ''
  //   }
  // }
}

export default {
  namespaced: true,
  state,
  mutations,
  getters
}
